/**
 * 自来水洗涤瓶
 */
ZiLaiShui = Widget.extend({
	ctor:function(){
		this._super();
		this.init();
		this.setTag(TAG_BOTTLE1);
	},
	init:function(){
		this.body = new Button(this, 10, TAG_ZILAISHUI, "#zilaishui.png", this.callback);
		this.body.setScale(0.7);
		var hand = new Button(this, 9, TAG_RIGHT, "#hand_right.png", this.callback);
		hand.setPosition(cc.p(30,-31));
		hand.setScale(0.7);
		hand.setVisible(false);
		var part = new Button(this, 11, TAG_RIGHT_PART, "#hand_right_part.png", this.callback);
		part.setPosition(cc.p(30,-31));
		part.setScale(0.7);
		part.setVisible(false);
		
		var label = new cc.LabelTTF("自来水",gg.fontName,22);
		label.setColor(cc.color(0,0,0));
		label.setPosition(44, 86);
		this.body.setCascadeOpacityEnabled(true);
		this.body.addChild(label, 11);
		
		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callNext.retain();
	},
	callback:function(p){
		var action=gg.flow.flow.action;
		var hand=this.getChildByTag(TAG_RIGHT);
		var part=this.getChildByTag(TAG_RIGHT_PART);
		var ddg=this.getParent().getChildByTag(TAG_DDG_DDG);
		var beaker=this.getParent().getChildByTag(TAG_BEAKER2);
		switch(p.getTag()){
		case TAG_ZILAISHUI:
			if(action==ACTION_DO1){				
				hand.setVisible(true);				
				part.setVisible(true);
				var move = cc.moveTo(0.6,cc.p(799,331));
				var rot = cc.rotateTo(0.6, 330);
				var rot1=cc.rotateTo(0.6, 0);
				var move1=cc.moveTo(0.6, cc.p(896,384));
				var seq = cc.sequence(move,rot,cc.callFunc(function(){
					this.getParent().water.flowRight(p,55,cc.p(10,220),1.5);
					ddg.lineUp(cc.p(-1,340));
				}, this),cc.delayTime(2),rot1,move1,cc.callFunc(function() {
					hand.setVisible(false);
					part.setVisible(false);
				}, this));
				this.runAction(seq);
				
				var seq2=cc.sequence(cc.rotateTo(0.6,30),cc.delayTime(2.4),cc.callFunc(function() {
					var pic=new cc.Sprite("#0_0_0.png");
					pic.setPosition(cc.p(89,138));
					pic.setScale(1.3);
					ddg.addChild(pic);
					
					var line=new cc.Sprite("#beaker_line.png");
					line.setPosition(cc.p(50,21));
					line.setRotation(-30);
					pic.addChild(line);
					line.runAction(cc.sequence(cc.moveTo(0.3, cc.p(50,72)),cc.delayTime(0.6),cc.rotateTo(0.6, 0)));
					
					pic.runAction(cc.sequence(cc.delayTime(2),cc.callFunc(function() {
						pic.removeFromParent()
					}, this)));
				}, this),cc.delayTime(1),cc.rotateTo(0.6, 0),cc.delayTime(0.5),this.callNext);
				ddg.runAction(seq2)
			}else if(action==ACTION_DO2){
				hand.setVisible(true);				
				part.setVisible(true);
				var move = cc.moveTo(0.6,cc.p(799,331));
				var rot = cc.rotateTo(0.6, 330);
				var rot1=cc.rotateTo(0.6, 0);
				var move1=cc.moveTo(0.6, cc.p(896,384));
				var seq = cc.sequence(move,rot,cc.callFunc(function(){
					this.getParent().water.flowRight(p,55,cc.p(10,220),1.5);
					ddg.lineUp(cc.p(1,70));
				}, this),cc.delayTime(2),rot1,move1,cc.callFunc(function() {
					this.removeFromParent();
				}, this),this.callNext);
				this.runAction(seq);
				
				var seq2=cc.sequence(cc.rotateTo(0.6,30),cc.delayTime(3),cc.rotateTo(0.6, 0));
				ddg.runAction(seq2)
			}else if(action==ACTION_DO3){
				hand.setVisible(true);				
				part.setVisible(true);
				var move = cc.moveTo(0.6,cc.p(1043,153));
				var rot = cc.rotateTo(0.6, 330);
				var rot1=cc.rotateTo(0.6, 0);
				var move1=cc.moveTo(0.6, cc.p(896,384));
				var seq = cc.sequence(move,rot,cc.callFunc(function(){
					this.getParent().water.flowRight(p,60,cc.p(10,220),1.5);
					beaker.lineUp(false,cc.p(0,30));
				}, this),cc.delayTime(2),rot1,move1,this.callNext,cc.callFunc(function() {
					this.removeFromParent();
				}, this));
				this.runAction(seq);
			}
			break;
		}
	},
	actionDone:function(p){
		switch(p.getTag()){
		case TAG_ZILAISHUI:	
			gg.flow.next();
			break;
		}
	},
	onExit:function(){
		this._super();
		this.callNext.release();
	}
});